﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace wjy自制小框架.Common.Pojo
{
    /// <summary>
    /// 通用返回
    /// wjy
    /// </summary>
    class AjaxResult
    {
        /// <summary>
        /// 错误码
        /// </summary>
        public int code { get; set; }

        /// <summary>
        /// 返回数据
        /// </summary>
        public object data { get; set; }

        /// <summary>
        /// 分页总数
        /// </summary>
        public long total { get; set; }

        /// <summary>
        /// 错误提示
        /// </summary>
        public string msg { get; set; }

        public static AjaxResult error(string msg = "系统异常")
        {
            return error(500, msg);
        }

        public static AjaxResult error(int code, string msg)
        {
            var result = new AjaxResult();
            result.code = code;
            result.msg = msg;
            return result;
        }

        public static AjaxResult success(object data = null)
        {
            var result = new AjaxResult();
            result.code = 200;
            result.data = data;
            result.msg = "";
            return result;
        }

        public static AjaxResult page(List<object> list, long total)
        {
            var result = new AjaxResult();
            result.code = 200;
            result.data = list;
            result.total = total;
            result.msg = "";
            return result;
        }
    }
}
